package likou;

/**
 * @author: 唐小尊
 * @email: 1171702529@qq.com
 * @cate: 2021/08/21 09:57
 */
public class _122 {
    public int maxProfit(int[] prices) {
        int[] states = new int[2];
        states[0] = -prices[0];
        for (int i = 1; i < prices.length; i++) {
            int pre1 = states[1];
            states[1] = Math.max(states[1], states[0] + prices[i]);
            states[0] = Math.max(states[0], pre1-prices[i]);
        }
        return states[1];
    }
    public int maxProfit2(int[] prices) {
        int res = 0;
        int n = prices.length;
        for(int i=0;i<n-1;i++){
            if(prices[i]<prices[i+1]){
                res = res + prices[i+1] - prices[i];
            }
        }
        return res;
    }
}
